#include <stdio.h>

int binary_search(int d[], int s, int e, int q)
{
    int mid, left = s, right = e;
    if (s >= e)
        return -1;
    while (left + 1 < right)
    {
        mid = (left + right) / 2;
        if (d[mid] >= q)
            right = mid;
        else
            left = mid;
    }
    //退出循环以后有可能 d[left] < q , 因此需要特殊处理
    //  如 (s,e,q) = (0,1,10) 且 d[0] = 5 的情形, left = 0, 但是应返回1
    if (d[left] >= q)
        return left - s;
    else
        return left - s + 1;
}

int a[20000];

int main()
{
    int i, n, m;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
        scanf("%d", a + i);
    scanf("%d", &m);
    for (i = 0; i < m; i++)
    {
        int s, e, q;
        scanf("%d%d%d", &s, &e, &q);
        printf("%d\n", binary_search(a, s, e, q));
    }
    return 0;
}

